package core

import (
	"os"

	"gopkg.in/yaml.v3"
)

type http struct {
	Listen string `yaml:"listen"`
}

type sqlite struct {
	Path string `yaml:"path"`
}

type postgres struct {
	Host     string `yaml:"host"`
	Port     string `yaml:"port"`
	User     string `yaml:"user"`
	Password string `yaml:"password"`
	DBName   string `yaml:"dbname"`
	TimeZone string `yaml:"time_zone"`
}

type ConfigModel struct {
	Name      string   `yaml:"name"`
	Http      http     `yaml:"http"`
	Database  string   `yaml:"database"`
	LogOutput string   `yaml:"log_output"`
	Sqlite    sqlite   `yaml:"sqlite"`
	Postgres  postgres `yaml:"postgres"`
}

func (m *ConfigModel) ParseConfig(config_file string) error {
	data, err := os.ReadFile(config_file)
	if err != nil {
		return err
	}
	err = yaml.Unmarshal(data, m)
	if err != nil {
		return err
	}
	return nil
}
